<template>
    <view class="wrap">
        <u-card>
            <view slot="head">
                <view class="nav-title__text">{{ info.cName }}</view>
            </view>
            <view slot="body">
                <view class="u-body-item u-flex u-border-bottom u-col-between u-p-t-0">
                    <view class="u-body-item-title u-line-2">竞赛开始时间：{{ info.cStartTime }}</view>
                </view>
                <view class="u-body-item u-flex u-border-bottom u-col-between u-p-t-0 ttp">
                    <view class="u-body-item-title u-line-2">竞赛类型：{{ info.cType }}</view>
                </view>
                <view class="u-body-item u-flex u-border-bottom u-col-between u-p-t-0 ttp">
                    <view class="u-body-item-title u-line-2">竞赛科目：{{ info.cSubject }}</view>
                </view>
                <view class="u-body-item u-flex u-border-bottom u-col-between u-p-t-0 ttp">
                    <view class="u-body-item-title u-line-2">竞赛场地：{{ info.cAdds }}</view>
                </view>
                <view class="u-body-item u-flex u-border-bottom u-col-between u-p-t-0 ttp">
                    <view class="u-body-item-title u-line-2">要求人数：{{ info.cNumbers }} [人]</view>
                </view>
                <view class="u-body-item u-flex u-border-bottom u-col-between u-p-t-0 ttp">
                    <view class="u-body-item-title u-line-2">竞赛时长：{{ info.cLangt }} [分钟]</view>
                </view>
                <view class="u-body-item u-flex u-border-bottom u-col-between u-p-t-0 ttp">
                    <view class="u-body-item-title u-line-2">注意事项：{{ info.cAbout }}</view>
                </view>
                <view class="u-body-item u-flex u-border-bottom u-col-between u-p-t-0 ttp">
                    <view class="u-body-item-title u-line-2">负责人：{{ info.cUser }}</view>
                </view>
                <view class="u-body-item u-flex u-border-bottom u-col-between u-p-t-0 ttp">
                    <view class="u-body-item-title u-line-2">联系方式：{{ info.cPhone }}</view>
                </view>
            </view>
        </u-card>
        <u-row gutter="16" justify="center" v-if="outbt && !isAdmin">
            <u-col span="10"><u-button type="primary" @click="sub" :ripple="true">报名</u-button></u-col>
        </u-row>
        <u-row gutter="16" justify="center" v-if="outbt && isAdmin">
            <u-table>
                <u-tr>
                    <u-th>报考人手机号</u-th>
                    <u-th>中考证号</u-th>
                    <u-th>竞赛科目</u-th>
                </u-tr>
                <u-tr v-for="(item, index) in users" :key="index">
                    <u-td>{{ item[6] }}</u-td>
                    <u-td>{{ item[0] }}</u-td>
                    <u-td>{{ item[2] }}</u-td>
                </u-tr>
            </u-table>
        </u-row>
        <u-select v-model="show" @confirm="confirm" :list="list"></u-select>
    </view>
</template>

<script>
export default {
    data() {
        return {
            info: '',
            user: {},
            outbt: false,
            isAdmin: false,
            show: false,
            list: [],
            users: []
        }
    },
    onLoad(opt) {
        this.info = JSON.parse(opt.p)
        JSON.parse(this.info.cSubject).forEach(v => {
            this.list.push({ value: v, label: v })
        })
        this.user = uni.getStorageSync('user_info')
        this.isLogin()
    },
    methods: {
        isLogin() {
            if (this.user && this.user.name.length > 0) {
                this.outbt = true
                if (this.user.admin == 1) {
                    this.isAdmin = true
                    this.initUsers()
                }
            } else {
                this.loginbutton = true
                this.outbt = false
            }
        },
        sub() {
            this.show = true
        },
        initUsers() {
            this.$u.post('/apps/ssResultsEntity/queryUser', { id: this.info.id }).then(res => {
                this.users = res
            })
        },
        confirm(e) {
            var select = ''
            e.map((val, index) => {
                select = val.value
            })
            var ps = {
                idCompettion: this.info.id,
                cSubject: select,
                idUser: this.user.id
            }
            this.$u.post('/apps/ssResultsEntity', ps).then(res => {
                if (res && res.code == 200) {
                    uni.showToast({
                        title: '报名成功',
                        duration: 2000
                    })
                    this.$u.route({
                        type: 'redirect',
                        url: 'pages/comp/comp_up'
                    })
                } else {
                    uni.showToast({
                        title: res.msg,
                        duration: 2000
                    })
                }
            })
        }
    }
}
</script>

<style lang="less" scoped>
.ttp {
    margin-top: 14rpx;
}
</style>
